package com.qf.homework.ex;

import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

@RestControllerAdvice
public class GlobalExHandler {

    @ExceptionHandler(Exception.class)
    public String ex(Exception ex){
        ex.printStackTrace();

        if (ex instanceof MaxUploadSizeExceededException || ex instanceof FileSizeLimitExceededException){
            return "文件大小不允许超过10M";
        }

        return "服务器忙，稍后重试~~";
    }
}
